//import {getxm,getxm1} from "api.js";
//import zzjg from "../../../../../themes/admin_default/xmgl/assets/utils/zzjg.js";
//import role from "../../../../../themes/admin_default/xmgl/assets/utils/role.js";
//import user from "../../../../../themes/admin_default/xmgl/assets/utils/userpublic.js";
//import { unixtimetostr } from "../../../../../themes/admin_default/xmgl/assets/utils/tools.js";

import tools from "../utils/tools.js";
import { unixtimetostr1 } from "../utils/tools.js";
import userservice from "../utils/userservice.js";
import xs from "../utils/xs.js";

axios.defaults.headers.post['Content-Type'] = 'application/json';

var Event = new Vue();//定义一个空的Vue实例 ，专门用来进行组件间通信

// 注册
Vue.component('xtest', {
    props: ['post'],
    template: '<h1>自定义组件!</h1>',
    data: function () {
        return {
            rootResourceTypeList: []
        };
    },
    mounted: function () {
        this.getRootResourceTypeList();
    },
    methods: {
    },
});

//挂载layer组件
Vue.use(LayerVue, {
    //此项设置置顶窗口的初始值，默认为100，一般无需配置，和其他组件冲突时可在此配置
    // 非置顶窗口请使用时单独设置
    zIndex: 100,
    //全局配置窗口皮肤
    skin: {
        //具体参数参见配置项：skin
    },
    //控制台打印相关信息
    log: true
});

var vm = new Vue({
    el: '#app',
    components: {
        // 局部注册，标签名称comp1
    },
    mounted: function () {
        // 访问组件的 DOM 元素
        //console.log(this.$el)
        let that = this;
        // 使用 $nextTick 方法访问父组件的数据
        this.$nextTick(() => {
            console.log('使用 $nextTick 方法访问父组件的数据', this.form)
            //console.log('unionid:', this.$refs.union_id.value);
            this.init_data();
        })
        // 监听数据变化
        this.$watch('data', () => {
            console.log('data changed');
        })
        // 在组件销毁时取消异步操作
        this.$once('hook:beforeDestroy', () => {
            that.cancelAsyncTask();
        })

    },
    data: function () {
        return {
            columnWidth: '90px',    //表格控制列宽度
            iserror: false,      //如果接口有错误，置true，不允许提交

            vs: {               //初始值
                xsArr: [],   //销售选择框值
                xsCascProps: {
                    multiple: false,        //多选开关
                    value: "id",
                    label: "user_nickname",
                },
                xsName: '',
            },

            queryRes: [],//用于搜索框的自动选择

            form1: {
                xsid: [],
                keyword: '',    //搜索关键字
            },

            tableData1: [],
        }
    },
    methods: {
        unixtimetostr1,

        tableHeaderColor({ row, column, rowIndex, columnIndex }) {
            if (rowIndex <= 1) {
                return 'background-color:rgb(68, 139, 226); color:#000000;'; //蓝色
            } else {
                return 'background-color: #ffffff; color:#000000;'
            }
        },
        changeXsCasc(e) {
            let that = this;
            that.vs.xsName = this.$refs.xsCasc.getCheckedNodes()[0].pathLabels[0];   //取得label
            that.searchData(that.form1.dateVal1, that.form1.xsid);
        },
        resetForm(form) {
            this.$refs[form].resetFields();
        },
        backurl() {
            window.history.back();  //返回上一页
        },

        querySearch(queryString , cb) {
            let queryRes = this.queryRes;
            let results = queryString ? queryRes.filter(this.createFilter(queryString)) : queryRes;
            // 调用 callback 返回建议列表的数据
            cb(results);
        },
        createFilter(queryString ) {
            return (restaurant) => {
                return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
            };
        },
        handleSelect(e) {
            console.log(e);
        },

        onSearch(e) {
            console.log(e);
        },

        onShowAll(e) {
            console.log(e);
        },
    },
});

//vm.unixtimetostr1 = tools.unixtimetostr1;
vm.init_data = function () {
    let that = this;

    //取得本机构所有销售人员
    userservice.getXsArr().then((res) => {
        console.log(res.data);
        that.vs.xsArr = res.data;
    }).catch((res) => {
        console.log(res.data);
    });

    queryRes = that.queryRes;
    that.queryRes = [
        { "value": "荆州", "address": "荆州1" },
        { "value": "潜江", "address": "潜江1" },
    ];

}

vm.searchData = function (dateVal1, user_id) {
    let that = this;
    let params = {
        djdate: dateVal1,
        userid: user_id
    };
    xs.indexxsgz(params).then((res) => {
        console.log('then:', res);
        this.$notify({
            message: '成功取到数据！',
            type: 'success'
        });
        that.tableData1 = res.data.comp1;
        that.tableData2 = res.data.comp2;
        that.tableData3 = res.data.comp3;
        that.tableData4 = res.data.comp4;
        that.tableData5 = res.data.comp5;
    })
        .catch((res) => {
            console.log('catch:', res);
            this.$notify({ message: res.msg, type: 'warning' });
            that.tableData1 = [];
            that.tableData2 = [];
            that.tableData3 = [];
            that.tableData4 = [];
            that.tableData5 = [];
        })
}


